package lovo.practice_7_14;

import lovo.FileUtil.FileUtil;
import lovo.Util.Util;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;


public class J189_7_14 extends JFrame {

    private TransPanel transPanel = new TransPanel(this);
    private LoginPanel loginPanel = new LoginPanel(this);
    private MunePanel munePanel = new MunePanel(this);
    private ScanPanel scanPanel = new ScanPanel(this);
    private SetPwdPanel setPwdPanel = new SetPwdPanel(this);
    private User users;


    public LoginPanel getLoginPanel() {
        return loginPanel;
    }

    public MunePanel getMunePanel() {
        return munePanel;
    }

    public ScanPanel getScanPanel() {
        return scanPanel;
    }

    public SavePanel getSavePanel() {
        return savePanel;
    }

    public GetPanel getGetPanel() {
        return getPanel;
    }

    public FindPanel getFindPanel() {
        return findPanel;
    }

    public User getUsers() {
        return users;
    }

    public void setUsers(User users) {
        this.users = users;
    }

    private SavePanel savePanel = new SavePanel(this);
    private GetPanel getPanel = new GetPanel(this);
    private FindPanel findPanel = new FindPanel(this);
    private List<User> listusers = new ArrayList();

    public List<User> getListusers() {
        return listusers;
    }

    public void setListusers(List<User> listusers) {
        this.listusers = listusers;
    }

    private Image ImageTitle = Util.getimages("/Images/微信图片_20220705124452.jpg");
    private Image ImageBack = Util.getimages("/Images/background.jpg");

    private CardLayout cardLayout = new CardLayout();

    public J189_7_14() {
        //1 设置背景图
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(ImageBack, 0, 0, 1024, 768, this);
            }
        });

        this.setLayout(cardLayout);

        //           2 设置登录按钮
        this.add("login", loginPanel);
        //               3 设置菜单card
        this.add("mune", munePanel);
        //4 存钱card
        this.add("save", savePanel);
        //5 取钱
        this.add("get", getPanel);
        // 6 查询
        this.add("find", findPanel);

        this.add("scan", scanPanel);

        this.add("trans", transPanel);
        this.add("setPwd", setPwdPanel);
        //0 初始化
        init();
        this.setSize(1024, 768);
        this.setTitle("银行管理系统");
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setIconImage(ImageTitle);
        this.setVisible(true);
        this.add("trans", transPanel);

    }


    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }


    public void init() {
        listusers = (ArrayList<User>) FileUtil.readObject("d:/atm.dat");
    }

    public void update() {
        FileUtil.writeObject("d:/atm.dat",listusers);
    }

    public void setMoney() {
        getFindPanel().getJLabelFind().setText(getUsers().getBalance() + "");
    }


    public static void main(String[] args) {
        J189_7_14 atm = new J189_7_14();
    }
}
